package com.feinno.urcs.group.siputils;

import com.feinno.sip.address.SipUri;
import com.feinno.urcs.group.GroupConfiguration;
import com.feinno.urcs.nai.IMPU;

import javax.sip.address.SipURI;
import javax.sip.address.TelURI;
import javax.sip.address.URI;

/**
 * Created by honghao on 5/11/15.
 */
public class URIUtils {
    public static String getMobileNo(URI uri) {
        if (uri == null) {
            return null;
        } else if (uri.isSipURI()) {
            return ((SipUri) uri).getUser();
        } else {
            return "+"+((TelURI) uri).getPhoneNumber();
        }
    }
    public static int getGroupIdFromUri(String groupUri) {
        URI uri = IMPU.parse(groupUri).toUri();
        if (uri.isSipURI()) {
            String gId = ((SipURI) uri).getUser().toString();
            return  Integer.parseInt(gId.substring(GroupConfiguration.INSTANCE.getGroupPrefix().length()));
        } else {
            return 0;
        }
    }

}
